import java.util.*;

import org.newdawn.slick.*;
import org.newdawn.slick.tiled.*;
import org.newdawn.slick.util.pathfinding.*;

public class Map {

	// locations in tiles of unmoving objects (exit, carrots)- the numbers are there for fun for now
	//	public final static int[] EXIT_LOCATION = {10, 10};
	//	public final static int[] CARROT_LOCATION = {5, 5};
	public final static int TILE_SIZE = 32;

	public static ArrayList<Entity> entitys;
	public static int[][] tiles;
	private TiledMap map;

	public Map(String mapPath) throws SlickException {
		entitys = new ArrayList<Entity>();
		map = new TiledMap(mapPath);
		readMap();
	}

	private void readMap() {

		tiles = new int[map.getHeight()][map.getWidth()];

		for (int x = 0; x < map.getWidth(); x++) {
			for (int y = 0; y < map.getHeight(); y++) {
				int tileID = map.getTileId(x, y, 0);

				String type = "";
				if(tileID != 0) {
					type = map.getTileProperty(tileID, "type", "solid");
				}

				if (type.equals("solid")) {
					tiles[y][x] = Tiles.SOLID;
				} else if(type.equals("hazard")) {
					tiles[y][x] = Tiles.HAZARD;
				} else if(type.equals("walkable")){
					tiles[y][x] = Tiles.WALKABLE;
				}
			}
		}
	}

	public void render() {
		map.render(0, 0);
	}




}

class SimpleMap implements TileBasedMap {

	public static int[][] MAP;
	
	private static int WIDTH;
	private static int HEIGHT;
	
	public SimpleMap(int[][] tiles) {
		MAP = tiles;
		WIDTH = MAP[0].length;
		HEIGHT = MAP.length;
	}

	@Override
	public boolean blocked(PathFindingContext ctx, int x, int y) {
		return MAP[y][x] == 0;
	}

	@Override
	public float getCost(PathFindingContext ctx, int x, int y) {
		return 1.0f;
	}

	@Override
	public int getHeightInTiles() {
		return HEIGHT;
	}

	@Override
	public int getWidthInTiles() {
		return WIDTH;
	}

	@Override
	public void pathFinderVisited(int x, int y) {}

}
